package com.xing.dao.impl;

import com.xing.dao.UserDao;
import com.xing.domain.User;
import com.xing.util.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.Connection;
import java.sql.SQLException;

/*
 * 静，谦虚谨慎，心胸宽广容纳所有好的坏的、先苦后甜
 * day39bookshop
 * 2021/4/29 14:13
 */
public class UserDaoImpl implements UserDao {
    private QueryRunner qr=new QueryRunner();
    @Override
    public User select(String username, String pwd) {
        Connection conn = DataSourceUtils.getConnection();
        String sql="select * from user where username=? and password=? ";
        try {
            return qr.query(conn,sql,new BeanHandler<>(User.class),username,pwd);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            DataSourceUtils.closeAll(null, null,conn);
        }
    }
}
